import { OneModal } from '@/components/one-ui';
import { IOneModalRef } from '@/pages/type';
import { fieldFlowExport, onCloseModalCommon } from '@/utils';
import moment from 'moment';
import { Ref, useRef } from 'react';
import { exportDeptRatioService } from '../services';

export const ExportModal = ({ onClose }) => {
  /**弹框的ref*/
  const modalRef: Ref<IOneModalRef> = useRef(null);

  /**导出接口*/
  const { exportDeptRatioRun, exportDeptRatioLoading } = exportDeptRatioService();

  /**弹窗确认按钮*/
  const onOk = () => {
    exportDeptRatioRun({})?.then((res) => {
      fieldFlowExport(res, `操作日志${moment()?.format('YYYYMMDDHHmmss')}.xlsx`);
      onCloseModalCommon(modalRef);
    });
  };
  return (
    <OneModal
      open={true}
      getContainer={false}
      ref={modalRef}
      title={'导出操作日志'}
      onCancel={onClose}
      onOk={onOk}
      width={document.body.clientWidth * 0.2}
      bodyStyle={{ padding: '5px 10px' }}
      confirmLoading={exportDeptRatioLoading}
    >
      <div style={{ lineHeight: '70px', textAlign: 'center' }}>确认是否导出操作日志!</div>
    </OneModal>
  );
};
